<?php
/**
 * CreateTime: 2023/11/21 14:06
 * User:LinQ
 */

namespace App\Models\Auth;

use App\Models\BasicModel;
use App\Models\Users\UsersModel;

class RoleModel extends BasicModel
{
    protected $table = 'role';

    protected $primaryKey = 'role_id';

    protected $fillable = [
        'role_id',
        'com_id',
        'role_name',
        'created_at',
        'updated_at',
    ];

    protected $casts = [
        'role_id' => 'integer',
        'com_id' => 'integer',
        'role_name' => 'string',
        'created_at' => 'string',
        'updated_at' => 'string',
    ];

    protected $hidden = [
        'created_at',
        'updated_at',
    ];

    /**
     * 获取角色下权限
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function auths(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
    {
        return $this->belongsToMany(AuthModel::class,'role_auth','role_id','auth_id');
    }

    /**
     * 获取角色下的用户
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function users() {
        return $this->belongsToMany(UsersModel::class, 'user_role','role_id','user_id');
    }

}